package com.sunwayworld.basemodule.common.asynctask.config;

import com.sunwayworld.framework.exception.InvalidDataException;
import com.sunwayworld.framework.utils.ObjectUtils;

public enum AsyncTaskStatusEnum {
    pendingAssign("pendingAssign", "待分配节点"),
    hasAssign("hasAssign", "已分配节点"),
    executing("executing", "执行中"),
    executeFail("executeFail", "执行失败"),
    executeSuccess("executeSuccess", "执行成功");

    public String status;
    public String statusDesc;

    AsyncTaskStatusEnum(String status, String statusDesc) {
        this.status = status;
        this.statusDesc = statusDesc;
    }

    public static AsyncTaskStatusEnum getStatus(AsyncTaskStatusEnum bean) {
        if (ObjectUtils.isEmpty(bean.status)) {
            throw new InvalidDataException("status is null");
        }
        AsyncTaskStatusEnum[] values = AsyncTaskStatusEnum.values();
        for (AsyncTaskStatusEnum s : values) {
            if (s.status.equals(bean.status)) {
                return s;
            }
        }
        throw new InvalidDataException("status not found:" + bean.status);
    }
}
